//
//  ZLHomeModel.m
//  ZLExamination
//
//  Created by Zheng on 2017/9/14.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLHomeModel.h"

@implementation ZLHomeNoticeModel;

- (void)setAttributes:(NSDictionary *)dataDic {
    [super setAttributes:dataDic];
    
    self.x_id = dataDic[@"id"];
}

@end

@implementation ZLHomeCourseLearningModel

- (void)setAttributes:(NSDictionary *)dataDic {
    [super setAttributes:dataDic];
    
    self.u_id = dataDic[@"id"];
    
    CGFloat p = [[NSString stringWithFormat:@"%.2f",self.learning_number.floatValue / self.chapter_number.floatValue] floatValue];

    p = p >= 1 ? 1:p;

    self.percent = p;
    
}

@end

@implementation ZLHomeModel

- (void)setAttributes:(NSDictionary *)dataDic {
    [super setAttributes:dataDic];
    
    self.sectionNumbers = 0;
    
    //0消息 1入矫 2常规 3解矫
    NSMutableArray *listType = [NSMutableArray new];

    NSMutableArray *listModelType0 = [NSMutableArray new];
    NSMutableArray *listModelType1 = [NSMutableArray new];
    NSMutableArray *listModelType2 = [NSMutableArray new];
    NSMutableArray *listModelType3 = [NSMutableArray new];
    
    NSMutableArray *lists = [NSMutableArray new];
    
    [lists addObject:listModelType1];
    [lists addObject:listModelType2];
    [lists addObject:listModelType3];
    
    //通知
    if ([self.notice_list count] > 0) {
        self.sectionNumbers++;
        [listType addObject:@(0)];
        
        [self.notice_list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx < 3) {
                ZLHomeNoticeModel *model = [[ZLHomeNoticeModel alloc] initWithDataDic:obj];
                [listModelType0 addObject:model];
            }
        }];
    }
    
    //课程
    [self.curriculum_list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj count] > 0) {
            self.sectionNumbers++;
            NSUInteger number = idx;
            
            [listType addObject:@(idx+1)];
            
            [obj enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                if (idx < 2) {
                    ZLHomeCourseLearningModel *model = [[ZLHomeCourseLearningModel alloc] initWithDataDic:obj];
                    [lists[number] addObject:model];
                } else {
                    *stop = YES;
                }
            }];
        }
    }];
    
    self.listType = [listType copy];
    
    lists = [NSMutableArray new];
    
    if (listModelType0.count > 0) {
        [lists addObject:listModelType0];
    }
    
    if (listModelType1.count > 0) {
        [lists addObject:listModelType1];
    }
    
    if (listModelType1.count > 0) {
        [lists addObject:listModelType1];
    }

    if (listModelType1.count > 0) {
        [lists addObject:listModelType1];
    }
    
    self.lists = [lists copy];

}

@end
